using UnityEngine;

public class Grid : MonoBehaviour
{
    public Color DefaultColor;
    public Color ClickedColor;
    public static float Width = 1;
    public static float Height = 1;
    GridMap parent = null;
    int row;
    int col;
    int id;

    public GridMap Parent { get => parent; set => parent = value; }
    public int Row { get => row; set => row = value; }
    public int Col { get => col; set => col = value; }
    public int Id { get => id; set => id = value; }

    Grid(GridMap p, int row, int col)
    {
        Parent = p;
        Row = row;
        Col = col;
    }
    // Start is called before the first frame update
    void Start()
    {
        Id = row * 10000 + col;
        gameObject.transform.localScale = new Vector3(Width, Height, 1);
        gameObject.GetComponent<MeshRenderer>().material.color = DefaultColor;
        //Debug.Log($"width: {Width}, Height: {Height}");
    }

    // Update is called once per frame
    void Update()
    {
    }

    public void OnMouseDown()
    {
        Debug.Log($"OnMouseDown, Row :{Row}, Col: {Col}");
        if (!parent.CommitGrid(this))
        {
            return;
        }
        gameObject.GetComponent<MeshRenderer>().material.color = ClickedColor;
    }

    public void Reset()
    {
        gameObject.GetComponent<MeshRenderer>().material.color = DefaultColor;
    }
}
